package com.yanqu.road.server.cmd.wingroom;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wingroom.WingRoomModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_WING_ROOM_CHANGE_BG_MUSIC, desc = "修改厢房背景音乐")
public class UserWingRoomChangeBgMusicCmd extends AbstractCommand {

    String music;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WingRoomProto.UserWingRoomChangeBgMusicReqMsg reqMsg = WingRoomProto.UserWingRoomChangeBgMusicReqMsg.parseFrom(packet.getBytes());
        music = reqMsg.getMusic();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WingRoomModule.class).changeMusic(music);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_WING_ROOM_CHANGE_BG_MUSIC, WingRoomProto.UserWingRoomChangeBgMusicRespMsg.newBuilder().setRet(ret));
        }
    }
}
